package com.atguigu.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.atguigu.common.GmallConfig;
import com.atguigu.common.GmallConfig_lj;
import redis.clients.jedis.Jedis;

import java.lang.reflect.InvocationTargetException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

/**
 * @Author 晶晶
 * @Date 2023 03 27 16 17
 **/
public class DimUtil_lj {
    public static JSONObject getDimInfo(Connection connection,String tableName,String id) throws Exception {

        //获取redis
//        Jedis jedis = JedisUtil.getJedis();
//        String redisKey = "DIM:"+tableName+" : "+id;
//        String dimInfoStr = jedis.get(redisKey);
//
//        if (dimInfoStr!=null){
//            jedis.expire(dimInfoStr,24*3600);
//            jedis.close();
//            return JSON.parseObject(dimInfoStr);
//        }


        String sql = "select * from "+ GmallConfig_lj.HBASE_SCHEMA +"."+tableName+" where id = '"+id+"' ";
        List<JSONObject> queryList = JdbcUtil_lj.getJdbcUtil(connection, sql, JSONObject.class, false);

        //System.out.println(sql);
        //System.out.println(queryList);
        //写入redis
        JSONObject dimInfo = queryList.get(0);
//        jedis.set(redisKey,dimInfo.toJSONString());
//        jedis.close();

        return dimInfo ;
    }
}
